package ch.jamme.conf;

/**
 * Defines the style used to marshall an objects' graph.
 * @author Mario Fusco
 */
public enum MarshallStyle {

	/**
	 * This is the default marshall style. It is the most verbose but also the only one that assures 
	 * that the resulting XML could be unmarshalled back in the graph from which it has been generated.
	 */
	BIDIRECTIONAL, 
	
	/**
	 * Each marshalled object is assigned with an unique id in order to avoid to marshall it more than once.
	 * No further informations about the actual classes of the marshalled objects is added to the xml, 
	 * but it is still possible to transform the xml back in the original objects graph if all the properties 
	 * of the objects are declared as concrete classes.
	 */
	REFERENCED, 
	
	/**
	 * No additional info is added to the marshalled objects. A given object is marshalled as many time 
	 * as it is present in the objects graph except if it is recursively nested in itself. In this last case 
	 * the marshall is just skipped in order to avoid an infinite recursion.
	 */
	RECURSION_SAFE, 
	
	/**
	 * The same as the recursion safe, with the difference that an Excption is thrown if a recursion is discovered.
	 */
	ERROR_ON_RECURSION;
	
	public boolean printObjectIds() {
		return this == BIDIRECTIONAL || this == REFERENCED;
	}
	
	public boolean checkLoops() {
		return this == RECURSION_SAFE || this == ERROR_ON_RECURSION;
	}
}
